package com.gy.hsim.bservice.userGroupingManagement.restful;

import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.weaver.patterns.IfPointcut.IfFalsePointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gy.hsim.bservice.framework.bean.QueryVerifyReponse;
import com.gy.hsim.bservice.framework.enums.MessageResultEnum;
import com.gy.hsim.bservice.framework.restful.BaseController;
import com.gy.hsim.bservice.message.bean.Message;
import com.gy.hsim.bservice.userGroupingManagement.bean.Group;
import com.gy.hsim.bservice.userGroupingManagement.bean.Member;
import com.gy.hsim.bservice.userGroupingManagement.bean.GroupVerify;
import com.gy.hsim.bservice.userGroupingManagement.bean.Notice;
import com.gy.hsim.bservice.userGroupingManagement.bean.PushGroupMsgBody;
import com.gy.hsim.bservice.userGroupingManagement.service.GroupService;

/**
 * 
 * @ClassName: GroupController 
 * @Description: 组群 Controller
 * @author quanrj 
 * @date 2015-12-11 上午09:57:19
 */
@Controller
@RequestMapping("/group")
public class GroupController extends BaseController{
	private static final Logger log = LoggerFactory
			.getLogger(Group.class);
	
	@Autowired
	private GroupService groupService;
	
	/**
	 * 添加群URL: http://localhost:8099/hsim-bservice/group/addGroup
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/addGroup",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse addGroup(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Group group = JSON.toJavaObject(object, Group.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Group group = JSON.toJavaObject(JSON.parseObject(jsonStr), Group.class);*/
			
			//校验必须的参数
			if(group.getGroupCreator() == null || group.getGroupCreator().equals("") || group.getGroupName() == null || group.getGroupName().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'groupCreator'和'groupName'都不能为空");
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验用户创建的群数量，如果超过设置的上限，则不能再创建
			if(!groupService.checkNumberLimit(2, group)){
				resp.setRetCode(MessageResultEnum.GROUPCREATE_COUNT_LIMIT.getRetCode());
				resp.setMessage(MessageResultEnum.GROUPCREATE_COUNT_LIMIT.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			//组装groupId
			String groupCreator = group.getGroupCreator();
			String groupId = groupService.setGroupId(groupCreator.substring(0,11));
			group.setGroupId(groupId);
			group.setGroupHost(group.getGroupCreator());
			
			/*Date now = new Date(); 
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");//可以方便地修改日期格式
			String dateStr = dateFormat.format(now);			
			String groupId = groupService.setGroupId(groupCreator, dateStr);
			group.setGroupId(groupId);*/
			
			/*String groupId = new String(groupCreator + dateStr);
			groupId = groupCreator + groupId.substring(groupId.length()-5,groupId.length());
			group.setGroupId(groupId);*/
			
			/*//群主创建群的时候也把自己添加到群成员信息中
			Member member = new Member();
			member.setMemberGroupId(group.getGroupId());
			member.setMemberUserId(group.getGroupCreator());
			member.setMemberVerificationBy(group.getGroupCreator());
			member.setMemberRole("H");
			member.setMemberUpdateBy(group.getGroupCreator());
			groupService.addUserIntoGroup(member);*/
			
			//创建群
			groupService.addGroup(group);
						
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(groupId);
			System.out.println("【创建群成功】：" + group.getGroupId());
			log.debug("【创建群成功】：" + group.getGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 根据群ID查询群信息URL: http://localhost:8099/hsim-bservice/group/queryGroupInfoByGroupId
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryGroupInfoByGroupId",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryGroupInfoByGroupId(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Group group = JSON.toJavaObject(object, Group.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Group group = JSON.toJavaObject(JSON.parseObject(jsonStr), Group.class);*/
			
			List<Group> groupInfoList = new ArrayList<Group>();
			groupInfoList = groupService.queryGroupInfoByGroupId(group);
			int totalRows = groupInfoList.size();
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setRows(groupInfoList);
			resp.setTotalRows(totalRows);
			System.out.println("【根据群ID查询群信息成功】：" + group.getGroupId());
			log.debug("【根据群ID查询群信息成功】：" + group.getGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 用户申请加入群前根据各种参数查询群信息URL: http://localhost:8099/hsim-bservice/group/queryGroupInfoByGroupParam
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryGroupInfoByGroupParam",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryGroupInfoByGroupParam(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Group group = JSON.toJavaObject(object, Group.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);
						
			Group group = JSON.toJavaObject(JSON.parseObject(jsonStr), Group.class);*/
			
			List<Group> groupInfoList = new ArrayList<Group>();
			groupInfoList = groupService.queryGroupInfoByGroupParam(group);
			int totalRows = groupInfoList.size();
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setRows(groupInfoList);
			resp.setTotalRows(totalRows);
			System.out.println("【搜索群信息成功】：" + totalRows);
			log.debug("【搜索群信息成功】：" + totalRows);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
			
	/**
	 * 根据用户ID查询群信息(查询用户拥有的群信息)URL: http://localhost:8099/hsim-bservice/group/queryGroupInfoByUserId
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryGroupInfoByUserId",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryGroupInfoByUserId(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Group group = JSON.toJavaObject(object, Group.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Group group = JSON.toJavaObject(JSON.parseObject(jsonStr), Group.class);*/
			
			List<Group> groupInfoList = new ArrayList<Group>();
			groupInfoList = groupService.queryGroupInfoByUserId(group);
			int totalRows = groupInfoList.size();
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setRows(groupInfoList);
			resp.setTotalRows(totalRows);
			System.out.println("【根据用户ID查询群信息成功】：" + group.getGroupCreator());
			log.debug("【根据用户ID查询群信息成功】：" + group.getGroupCreator());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 更新群信息URL: http://localhost:8099/hsim-bservice/group/updateGroupInfo
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/updateGroupInfo",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse updateGroupInfo(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Group group = JSON.toJavaObject(object, Group.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Group group = JSON.toJavaObject(JSON.parseObject(jsonStr), Group.class);*/
			
			//校验必须的参数
			if(group.getGroupId() == null || group.getGroupId().equals("") || group.getGroupName() == null || group.getGroupName().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'groupId'和'groupName'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
												
			groupService.updateGroupInfo(group);
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【更新群成功】：" + group.getGroupId());
			log.debug("【更新群成功】：" + group.getGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 删除群URL: http://localhost:8099/hsim-bservice/group/deleteGroup
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/deleteGroup",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse deleteGroup(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Group group = JSON.toJavaObject(object, Group.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Group group = JSON.toJavaObject(JSON.parseObject(jsonStr), Group.class);*/
			
			//校验必须的参数
			if(group.getGroupId() == null || group.getGroupId().equals("") 
					|| group.getGroupName() == null || group.getGroupName().equals("")
					|| group.getGroupHost() == null || group.getGroupHost().equals("")
					|| group.getGroupCreatorNickname() == null || group.getGroupCreatorNickname().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'groupId'、'groupHost'、'groupCreatorNickname'和'groupName'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验用户是否具备操作权限，如果不是群主，则不能进行操作
			Member memberQueryRoleParam = new Member();
			memberQueryRoleParam.setMemberGroupId(group.getGroupId());
			memberQueryRoleParam.setMemberUserId(group.getGroupHost());
			String memberRole = groupService.queryUserRoleInGroup(memberQueryRoleParam);
			if(!(memberRole.equals("H"))){
				resp.setRetCode(MessageResultEnum.INSUFFICIENT_AUTHORITY.getRetCode());
				resp.setMessage(MessageResultEnum.INSUFFICIENT_AUTHORITY.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			//删除群
			groupService.deleteGroup(group);
			
			//发送删除群消息到网关
			Member member = new Member();
			member.setMemberGroupId(group.getGroupId());
			member.setMemberGroupName(group.getGroupName());
			member.setMemberUpdateBy(group.getGroupHost());
			member.setMemberManagerNickName(group.getGroupCreatorNickname());
			groupService.groupPushMsg(member, 8);
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【删除群成功】：" + group.getGroupId());
			log.debug("【删除群成功】：" + group.getGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 用户申请加入群: http://localhost:8099/hsim-bservice/group/joinGroupReq
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/joinGroupReq",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse joinGroupReq(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("") 
					|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
					|| member.getMemberGroupName() == null || member.getMemberGroupName().equals("")
					|| member.getMemberNickName() == null || member.getMemberNickName().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberNickName'、'memberUserId'和'memberGroupName'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			//发送请求加入群消息到网关
			groupService.groupPushMsg(member, 1);
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());			
			System.out.println("【请求加入群成功】：" + member.getMemberGroupId());
			log.debug("【请求加入群成功】：" + member.getMemberGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 把用户加入群URL: http://localhost:8099/hsim-bservice/group/addUserIntoGroup
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/addUserIntoGroup",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse addUserIntoGroup(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("") 
					|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
					|| member.getMemberVerificationBy() == null || member.getMemberVerificationBy().equals("")
					|| member.getMemberVerifyId() == null || member.getMemberVerifyId().equals("")
					|| member.getMemberNickName() == null || member.getMemberNickName().equals("")
					|| member.getMemberManagerNickName() == null || member.getMemberManagerNickName().equals("")
					|| member.getMemberGroupName() == null || member.getMemberGroupName().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberVerifyId'、'memberNickName','memberManagerNickName','memberGroupName','memberUserId'和'memberVerificationBy'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			member.setMemberUpdateBy(member.getMemberVerificationBy());
			
			//校验群是否存在
			Group group = new Group();
			group.setGroupId(member.getMemberGroupId());
			List<Group> groupList = new ArrayList<Group>();
			groupList = groupService.queryGroupInfoByGroupId(group);
			if(groupList == null || groupList.size() == 0){
				resp.setRetCode(MessageResultEnum.GROUP_IS_UNACTIVE.getRetCode());
				resp.setMessage(MessageResultEnum.GROUP_IS_UNACTIVE.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			//检验群人数是否已经达到上限
			if(!groupService.checkNumberLimit(1, member)){
				resp.setRetCode(MessageResultEnum.GROUPMEMBER_COUNT_LIMIT.getRetCode());
				resp.setMessage(MessageResultEnum.GROUPMEMBER_COUNT_LIMIT.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验用户加入的群数量是否已经达到上限
			if(!groupService.checkNumberLimit(3, member)){
				resp.setRetCode(MessageResultEnum.GROUPJOIN_COUNT_LIMIT.getRetCode());
				resp.setMessage(MessageResultEnum.GROUPJOIN_COUNT_LIMIT.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验操作者用户在某个群的权限，不是管理员角色不能把用户加入群或做验证操作
			Member memberQueryRoleParam = new Member();
			memberQueryRoleParam.setMemberGroupId(member.getMemberGroupId());
			memberQueryRoleParam.setMemberUserId(member.getMemberVerificationBy());
			String memberRole = groupService.queryUserRoleInGroup(memberQueryRoleParam);
			if(!(memberRole.equals("H") || memberRole.equals("M"))){
				resp.setRetCode(MessageResultEnum.INSUFFICIENT_AUTHORITY.getRetCode());
				resp.setMessage(MessageResultEnum.INSUFFICIENT_AUTHORITY.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			//查询被添加用户是否已在群中，防止用户重复加入
			Member memberQueryUserInGroupParam = new Member();
			memberQueryUserInGroupParam.setMemberGroupId(member.getMemberGroupId());
			memberQueryUserInGroupParam.setMemberUserId(member.getMemberUserId());
			int userRows = groupService.queryIfUserInGroup(memberQueryUserInGroupParam);
			if(userRows > 0){
				resp.setRetCode(MessageResultEnum.USER_IN_GROUP.getRetCode());
				resp.setMessage(MessageResultEnum.USER_IN_GROUP.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验验证信息是否能进行验证,如果此信息被验证过或者已经失效则不能够进行验证
			GroupVerify groupVerify = new GroupVerify();
			groupVerify.setVerifyId(member.getMemberVerifyId());
			List<GroupVerify> groupVerifyList = new ArrayList<GroupVerify>();
			groupVerifyList = groupService.queryVerifyInfoByVerifyId(groupVerify);
			GroupVerify groupVerifyInList = groupVerifyList.get(0);
			String verifyResult = groupVerifyInList.getVerifyResult();
			if(verifyResult.equals("N") || verifyResult.equals("Y")){   //当verifyResult为Y或者为N的时候，说明已经被验证过，不能进行验证操作
				resp.setRetCode(MessageResultEnum.REQ_VERIFIED.getRetCode());
				resp.setMessage(MessageResultEnum.REQ_VERIFIED.getMessage());
				log.debug(resp.getMessage());
				return resp;
			} else {
				//校验此验证信息是否失效，如果失效则不能被验证
				String verifyReqDateStr = groupVerifyInList.getVerifyReqDate();  //从数据中得到请求验证的时间字符串				
				int result = groupService.checkVerifyInfoOutDate(verifyReqDateStr);  //校验验证信息是否失效
				if(result < 0){		//验证信息失效，不能进行验证操作
					resp.setRetCode(MessageResultEnum.REQ_VOVERDUE_DATE.getRetCode());
					resp.setMessage(MessageResultEnum.REQ_VOVERDUE_DATE.getMessage());
					log.debug(resp.getMessage());
					return resp;
				}
			}
			
			groupService.addUserIntoGroup(member);
			
			//发送同意用户加入群消息到网关 
			groupService.groupPushMsg(member, 2);
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【加入群成功】：" + member.getMemberGroupId());
			log.debug("【加入群成功】：" + member.getMemberGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 拒绝用户加入群URL: http://localhost:8099/hsim-bservice/group/refuseUserJoinGroup
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/refuseUserJoinGroup",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse refuseUserJoinGroup(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("") 
					|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
					|| member.getMemberVerificationBy() == null || member.getMemberVerificationBy().equals("")
					|| member.getMemberVerifyId() == null || member.getMemberVerifyId().equals("")
					|| member.getMemberNickName() == null || member.getMemberNickName().equals("")
					|| member.getMemberManagerNickName() == null || member.getMemberManagerNickName().equals("")
					|| member.getMemberGroupName() == null || member.getMemberGroupName().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberVerifyId'、'memberNickName','memberManagerNickName','memberGroupName()','memberUserId'和'memberVerificationBy'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			member.setMemberUpdateBy(member.getMemberVerificationBy());
												
			//校验操作者用户在某个群的权限，不是管理员角色不能把用户加入群或做验证操作
			Member memberQueryRoleParam = new Member();
			memberQueryRoleParam.setMemberGroupId(member.getMemberGroupId());
			memberQueryRoleParam.setMemberUserId(member.getMemberVerificationBy());
			String memberRole = groupService.queryUserRoleInGroup(memberQueryRoleParam);
			if(!(memberRole.equals("H") || memberRole.equals("M"))){
				resp.setRetCode(MessageResultEnum.INSUFFICIENT_AUTHORITY.getRetCode());
				resp.setMessage(MessageResultEnum.INSUFFICIENT_AUTHORITY.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验验证信息是否能进行验证,如果此信息被验证过或者已经失效则不能够进行验证
			GroupVerify groupVerify = new GroupVerify();
			groupVerify.setVerifyId(member.getMemberVerifyId());
			List<GroupVerify> groupVerifyList = new ArrayList<GroupVerify>();
			groupVerifyList = groupService.queryVerifyInfoByVerifyId(groupVerify);
			GroupVerify groupVerifyInList = groupVerifyList.get(0);
			String verifyResult = groupVerifyInList.getVerifyResult();
			if(verifyResult.equals("N") || verifyResult.equals("Y")){   //当verifyResult为Y或者为N的时候，说明已经被验证过，不能进行验证操作
				resp.setRetCode(MessageResultEnum.REQ_VERIFIED.getRetCode());
				resp.setMessage(MessageResultEnum.REQ_VERIFIED.getMessage());
				log.debug(resp.getMessage());
				return resp;
			} else {
				//校验此验证信息是否失效，如果失效则不能被验证
				String verifyReqDateStr = groupVerifyInList.getVerifyReqDate();  //从数据中得到请求验证的时间字符串				
				int result = groupService.checkVerifyInfoOutDate(verifyReqDateStr);  //校验验证信息是否失效
				if(result < 0){		//验证信息失效，不能进行验证操作
					resp.setRetCode(MessageResultEnum.REQ_VOVERDUE_DATE.getRetCode());
					resp.setMessage(MessageResultEnum.REQ_VOVERDUE_DATE.getMessage());
					log.debug(resp.getMessage());
					return resp;
				}
			}
			
			//拒绝用户加入群
			groupService.refuseUserJoinGroup(member);
			
			//发送拒绝用户加入群消息到网关 
			groupService.groupPushMsg(member, 3);
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【拒绝加入群成功】：" + member.getMemberGroupId());
			log.debug("【拒绝加入群成功】：" + member.getMemberGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 查询用户是否已在群中URL: http://localhost:8099/hsim-bservice/group/queryIfUserInGroup
	 * totalRows大于0说明已经在群中
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryIfUserInGroup",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryIfUserInGroup(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("") 
					|| member.getMemberUserId() == null || member.getMemberUserId().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberUserId'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
						
			int totalRows = groupService.queryIfUserInGroup(member);
									
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setTotalRows(totalRows);
			System.out.println("【查询用户是否在群中成功】：" + member.getMemberUserId());
			log.debug("【查询用户是否在群中成功】：" + member.getMemberUserId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}	
	
	/**
	 * 更新群成员信息URL: http://localhost:8099/hsim-bservice/group/updateMemberInfo
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/updateMemberInfo",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse updateMemberInfo(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数(根据更新类别进行校验)
			if(member.getMemberUpdateType() == null || member.getMemberUpdateType().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberUpdateType'不能为空!");
				log.debug(resp.getMessage());
				return resp;
			} else {
				if (member.getMemberUpdateType().equals("1")) {
					if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("")
							|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
							|| member.getMemberUpdateBy() == null || member.getMemberUpdateBy().equals("")){
						resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
						resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberUserId'和'memberUpdateBy'都不能为空!");
						log.debug(resp.getMessage());
						return resp;
					}
				} else if (member.getMemberUpdateType().equals("2")) {
					if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("")
							|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
							|| member.getMemberUpdateBy() == null || member.getMemberUpdateBy().equals("")
							|| member.getMemberRole() == null || member.getMemberRole().equals("")
							|| member.getMemberGroupName() == null || member.getMemberGroupName().equals("")
							|| member.getMemberNickName() == null || member.getMemberNickName().equals("")
							|| member.getMemberManagerNickName() == null || member.getMemberManagerNickName().equals("")){
						resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
						resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberGroupName'、'memberUserId'、'memberNickName'、'memberRole'、'memberManagerNickName'、'memberUpdateBy'和'memberUpdateType'都不能为空!");
						log.debug(resp.getMessage());
						return resp;
					}
				} else if (member.getMemberUpdateType().equals("3")) {					
					if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("")
							|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
							|| member.getMemberUpdateBy() == null || member.getMemberUpdateBy().equals("")
							|| member.getMemberSilenceFlag() == null || member.getMemberSilenceFlag().equals("")){
						resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
						resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberSilenceFlag'、'memberUserId'和'memberUpdateBy'都不能为空!");
						log.debug(resp.getMessage());
						return resp;
					}
				} else if (member.getMemberUpdateType().equals("4")) {
					if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("")
							|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
							|| member.getMemberUpdateBy() == null || member.getMemberUpdateBy().equals("")){
						resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
						resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberUserId'和'memberUpdateBy'都不能为空!");
						log.debug(resp.getMessage());
						return resp;
					}
				} else {
					
				}
			}
								
			//校验操作人是否具备操作权限
			//更新类型,1.成员设置群名片 2.群主设置管理员  3.群管理员对普通成员设置禁言  4.群管理员对群成员进行备注
			if(!(member.getMemberUpdateType().equals("1"))){  //1.成员设置群名片 ，任何角色都可以
				if(member.getMemberUpdateType().equals("2")){ //2.群主设置管理员，操作者必须是群主角色
					
					//如果是把普通成员设置成管理员，校验管理员数目是否已经达到上限
					if(member.getMemberRole().equals("M")){
						if(!groupService.checkNumberLimit(4, member)){
							resp.setRetCode(MessageResultEnum.GROUPMANAGER_COUNT_LIMIT.getRetCode());
							resp.setMessage(MessageResultEnum.GROUPMANAGER_COUNT_LIMIT.getMessage());
							log.debug(resp.getMessage());
							return resp;
						}
					}
					
					//校验用户是否在群中
					Member memberQueryUserInGroupParam = new Member();
					memberQueryUserInGroupParam.setMemberGroupId(member.getMemberGroupId());
					memberQueryUserInGroupParam.setMemberUserId(member.getMemberUserId());
					int userRows = groupService.queryIfUserInGroup(memberQueryUserInGroupParam);
					if(userRows == 0){
						resp.setRetCode(MessageResultEnum.USER_NOT_INGROUP.getRetCode());
						resp.setMessage(MessageResultEnum.USER_NOT_INGROUP.getMessage());
						log.debug(resp.getMessage());
						return resp;
					}
										
					//如果不是群主，则不能设置管理员
					Member memberIfHostParam = new Member();
					memberIfHostParam.setMemberGroupId(member.getMemberGroupId());
					memberIfHostParam.setMemberUserId(member.getMemberUpdateBy());
					String memberRole = groupService.queryUserRoleInGroup(memberIfHostParam);
					if(!memberRole.equals("H")){
						resp.setRetCode(MessageResultEnum.INSUFFICIENT_AUTHORITY.getRetCode());
						resp.setMessage(MessageResultEnum.INSUFFICIENT_AUTHORITY.getMessage());
						log.debug(resp.getMessage());
						return resp;
					}
				} else if (member.getMemberUpdateType().equals("3") || member.getMemberUpdateType().equals("4")) {
					//3.群管理员对普通成员设置禁言  4.群管理员对群成员进行备注  这些操作需要操作者具备管理员角色并且被设置对象为群普通成员
					Member memberIfManagerParam = new Member();
					memberIfManagerParam.setMemberGroupId(member.getMemberGroupId());
					memberIfManagerParam.setMemberUserId(member.getMemberUpdateBy());
					String memberRoleOnSetway = groupService.queryUserRoleInGroup(memberIfManagerParam);
					if(!(memberRoleOnSetway.equals("H") || memberRoleOnSetway.equals("M"))){
						resp.setRetCode(MessageResultEnum.INSUFFICIENT_AUTHORITY.getRetCode());
						resp.setMessage(MessageResultEnum.INSUFFICIENT_AUTHORITY.getMessage());
						log.debug(resp.getMessage());
						return resp;
					} else {
						memberIfManagerParam.setMemberUserId(member.getMemberUserId());
						String memberRoleOnUserway = groupService.queryUserRoleInGroup(memberIfManagerParam);
						if(!memberRoleOnUserway.equals("N")){
							resp.setRetCode(MessageResultEnum.NOT_GROUP_NORMAL_MEMBER.getRetCode());
							resp.setMessage(MessageResultEnum.NOT_GROUP_NORMAL_MEMBER.getMessage());
							log.debug(resp.getMessage());
							return resp;
						}
					}
				} else {
					resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
					resp.setMessage("memberUpdateType参数数据错误!");
					log.debug(resp.getMessage());
					return resp;
				}
			}
						
			groupService.updateMemberInfo(member);
			
			//发送设置管理员消息到网关
			if(member.getMemberUpdateType().equals("2")){
				if(member.getMemberRole().equals("M")){   //设置管理员
					groupService.groupPushMsg(member, 6);
				} else if (member.getMemberRole().equals("N")) {  //取消管理员
					groupService.groupPushMsg(member, 7);
				}
			}
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【更新群成员信息成功】：" + member.getMemberUserId());
			log.debug("【更新群成员信息成功】：" + member.getMemberUserId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 查询用户所在的群信息URL: http://localhost:8099/hsim-bservice/group/queryGroupInfoUserJoin
	 * @DESC 查询用户加入的群memberRole传"N",查询用户管理的群memberRole传"M",查询用户创建的群memberRole传"H"
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryGroupInfoUserJoin",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryGroupInfoUserJoin(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数
			if(member.getMemberUserId() == null || member.getMemberUserId().equals("")
					|| member.getMemberRole() == null || member.getMemberRole().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberUserId'和'memberRole'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			List<Group> groupInfoList = new ArrayList<Group>();
			groupInfoList = groupService.queryGroupInfoUserJoin(member);
			int totalRows = groupInfoList.size();
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setRows(groupInfoList);
			resp.setTotalRows(totalRows);
			System.out.println("【根据用户ID查询所在群的群成员信息成功】：" + member.getMemberUserId());
			log.debug("【根据用户ID查询所在群的群成员信息成功】：" + member.getMemberUserId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 根据群ID查询群的成员信息URL: http://localhost:8099/hsim-bservice/group/queryMemberInfoByGroupId
	 * @DESC 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryMemberInfoByGroupId",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryMemberInfoByGroupId(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);
			*/
			//校验必须的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("")
					|| member.getMemberUserId() == null || member.getMemberUserId().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberUserId'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			List<Member> memberInfoList = new ArrayList<Member>();
			memberInfoList = groupService.queryMemberInfoByGroupId(member);
			//如果用户在群中不是管理员角色，查看不到群成员中的成员备注信息
			Member memberIfManagerParam = new Member();
			memberIfManagerParam.setMemberGroupId(member.getMemberGroupId());
			memberIfManagerParam.setMemberUserId(member.getMemberUserId());
			String memberRoleOnSetway = groupService.queryUserRoleInGroup(memberIfManagerParam);
			if(memberRoleOnSetway == null || memberRoleOnSetway.equals("")){
				resp.setRetCode(MessageResultEnum.USER_NOT_INGROUP.getRetCode());
				resp.setMessage(MessageResultEnum.USER_NOT_INGROUP.getMessage());
				log.debug(resp.getMessage());
				return resp;
			} else {
				if(!(memberRoleOnSetway.equals("M") || memberRoleOnSetway.equals("H"))){
					for(Member memberInListMember : memberInfoList){
						memberInListMember.setMemberUserRemark("");					
					}
				}
			}
						
			int totalRows = memberInfoList.size();
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setRows(memberInfoList);
			resp.setTotalRows(totalRows);
			System.out.println("【根据群ID查询群的成员信息成功】：" + member.getMemberGroupId());
			log.debug("【根据群ID查询群的成员信息成功】：" + member.getMemberGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 根据群ID查询群解散后的成员信息URL: http://localhost:8099/hsim-bservice/group/queryMemberInfoAfterGroupDelete
	 * @DESC 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryMemberInfoAfterGroupDelete",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryMemberInfoAfterGroupDelete(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必须的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			List<Member> memberInfoList = new ArrayList<Member>();
			memberInfoList = groupService.queryMemberInfoAfterGroupDelete(member);
			
			int totalRows = memberInfoList.size();
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setRows(memberInfoList);
			resp.setTotalRows(totalRows);
			System.out.println("【根据群ID查询群的成员信息成功】：" + member.getMemberGroupId());
			log.debug("【根据群ID查询群的成员信息成功】：" + member.getMemberGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 根据群ID查询群的所有管理员信息URL: http://localhost:8099/hsim-bservice/group/queryAllManagerInfoByGroupId
	 * @DESC 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryAllManagerInfoByGroupId",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryAllManagerInfoByGroupId(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必须的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			List<Member> memberInfoList = new ArrayList<Member>();
			memberInfoList = groupService.queryAllManagerInfoByGroupId(member);						
			int totalRows = memberInfoList.size();
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setRows(memberInfoList);
			resp.setTotalRows(totalRows);
			System.out.println("【根据群ID查询所有管理员信息成功】：" + member.getMemberGroupId());
			log.debug("【根据群ID查询所有管理员信息成功】：" + member.getMemberGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 查询用户在某个群是否被禁言URL: http://localhost:8099/hsim-bservice/group/queryUserSilenceFlag
	 * @DESC 根据VerifyFlag,Y表示被禁言,N表示未被禁言
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryUserSilenceFlag",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryUserSilenceFlag(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("")
					|| member.getMemberUserId() == null || member.getMemberUserId().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'和'memberUserId'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
									
			String silenceFlag = groupService.queryUserSilenceFlag(member);   //Y表示被禁言,N表示未被禁言
			resp.setVerifyFlag(silenceFlag);
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【根据用户ID查询所在群中是否被禁言成功】：" + member.getMemberUserId());
			log.debug("【根据用户ID查询所在群中是否被禁言成功】：" + member.getMemberUserId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 管理员删除群成员URL: http://localhost:8099/hsim-bservice/group/deleteMemberInGroup
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/deleteMemberInGroup",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse deleteMemberInGroup(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("") 
					|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
					|| member.getMemberUpdateBy() == null || member.getMemberUpdateBy().equals("")
					|| member.getMemberNickName() == null || member.getMemberNickName().equals("")
					|| member.getMemberManagerNickName() == null || member.getMemberManagerNickName().equals("")
					|| member.getMemberGroupName() == null || member.getMemberGroupName().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId'、'memberNickName','memberManagerNickName','memberGroupName','memberUserId'和'memberUpdateBy'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验是否具备操作权限
			Member memberIfManagerParam = new Member();
			memberIfManagerParam.setMemberGroupId(member.getMemberGroupId());
			memberIfManagerParam.setMemberUserId(member.getMemberUpdateBy());
			String memberRoleOnSetway = groupService.queryUserRoleInGroup(memberIfManagerParam);
			if(!(memberRoleOnSetway.equals("H") || memberRoleOnSetway.equals("M"))){
				resp.setRetCode(MessageResultEnum.INSUFFICIENT_AUTHORITY.getRetCode());
				resp.setMessage(MessageResultEnum.INSUFFICIENT_AUTHORITY.getMessage());
				log.debug(resp.getMessage());
				return resp;
			} else {
				memberIfManagerParam.setMemberUserId(member.getMemberUserId());
				String memberRoleOnUserway = groupService.queryUserRoleInGroup(memberIfManagerParam);
				if(!memberRoleOnUserway.equals("N")){
					resp.setRetCode(MessageResultEnum.NOT_GROUP_NORMAL_MEMBER.getRetCode());
					resp.setMessage(MessageResultEnum.NOT_GROUP_NORMAL_MEMBER.getMessage());
					log.debug(resp.getMessage());
					return resp;
				}
			}
			
			//校验用户是否在群中
			Member memberQueryUserInGroupParam = new Member();
			memberQueryUserInGroupParam.setMemberGroupId(member.getMemberGroupId());
			memberQueryUserInGroupParam.setMemberUserId(member.getMemberUserId());
			int userRows = groupService.queryIfUserInGroup(memberQueryUserInGroupParam);
			if(userRows == 0){
				resp.setRetCode(MessageResultEnum.USER_NOT_INGROUP.getRetCode());
				resp.setMessage(MessageResultEnum.USER_NOT_INGROUP.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
						
			groupService.deleteMemberInGroup(member);
			
			//发送删除用户消息到网关
			groupService.groupPushMsg(member, 4);
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【删除群成员成功】：" + member.getMemberUserId());
			log.debug("【删除群成员成功】：" + member.getMemberUserId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 群成员离开群URL: http://localhost:8099/hsim-bservice/group/memberLeaveGroup
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/memberLeaveGroup",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse memberLeaveGroup(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("") 
					|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
					|| member.getMemberNickName() == null || member.getMemberNickName().equals("")
					|| member.getMemberGroupName() == null || member.getMemberGroupName().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId','memberNickName','memberGroupName'和'memberUserId'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			member.setMemberUpdateBy(member.getMemberUserId());
			
			//校验用户是否在群中
			Member memberQueryUserInGroupParam = new Member();
			memberQueryUserInGroupParam.setMemberGroupId(member.getMemberGroupId());
			memberQueryUserInGroupParam.setMemberUserId(member.getMemberUserId());
			int userRows = groupService.queryIfUserInGroup(memberQueryUserInGroupParam);
			if(userRows == 0){
				resp.setRetCode(MessageResultEnum.USER_NOT_INGROUP.getRetCode());
				resp.setMessage(MessageResultEnum.USER_NOT_INGROUP.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
												
			groupService.deleteMemberInGroup(member);
			
			//发送删除用户消息到网关
			groupService.groupPushMsg(member, 5);
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【离开群操作成功】：" + member.getMemberUserId());
			log.debug("【离开群操作成功】：" + member.getMemberUserId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 群主转让群URL: http://localhost:8099/hsim-bservice/group/memberTransferHost
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/memberTransferHost",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse memberTransferHost(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Member member = JSON.toJavaObject(object, Member.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Member member = JSON.toJavaObject(JSON.parseObject(jsonStr), Member.class);*/
			
			//校验必要的参数
			if(member.getMemberGroupId() == null || member.getMemberGroupId().equals("") 
					|| member.getMemberUserId() == null || member.getMemberUserId().equals("")
					|| member.getMemberUpdateBy() == null || member.getMemberUpdateBy().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'memberGroupId','memberUserId'和'memberUpdateBy'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验操作权限
			Member memberIfManagerParam = new Member();
			memberIfManagerParam.setMemberGroupId(member.getMemberGroupId());
			memberIfManagerParam.setMemberUserId(member.getMemberUpdateBy());
			String memberRoleOnSetway = groupService.queryUserRoleInGroup(memberIfManagerParam);
			if(memberRoleOnSetway == null || !(memberRoleOnSetway.equals("H"))){
				resp.setRetCode(MessageResultEnum.INSUFFICIENT_AUTHORITY.getRetCode());
				resp.setMessage(MessageResultEnum.INSUFFICIENT_AUTHORITY.getMessage());
				log.debug(resp.getMessage());
				return resp;
			} else{
				Member memberQueryUserInGroupParam = new Member();
				memberQueryUserInGroupParam.setMemberGroupId(member.getMemberGroupId());
				memberQueryUserInGroupParam.setMemberUserId(member.getMemberUserId());
				int userRows = groupService.queryIfUserInGroup(memberQueryUserInGroupParam);
				if(userRows == 0){  //用户不在群中,不能做转让操作
					resp.setRetCode(MessageResultEnum.USER_NOT_INGROUP.getRetCode());
					resp.setMessage(MessageResultEnum.USER_NOT_INGROUP.getMessage());
					log.debug(resp.getMessage());
					return resp;
				}
			}
			
			groupService.memberTransferHost(member);
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【转让群成功】：" + member.getMemberGroupId());
			log.debug("【转让群成功】：" + member.getMemberGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 插入验证信息URL: http://localhost:8099/hsim-bservice/group/addGroupVerifyInfo
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/addGroupVerifyInfo",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse addVerifyInfo(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			GroupVerify groupVerify = JSON.toJavaObject(object, GroupVerify.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			GroupVerify groupVerify = JSON.toJavaObject(JSON.parseObject(jsonStr), GroupVerify.class);*/
			
			//校验必要的参数
			if(groupVerify.getVerifyId() == null || groupVerify.getVerifyId().equals("") 
					|| groupVerify.getVerifyGroupId() == null || groupVerify.getVerifyGroupId().equals("")
					|| groupVerify.getVerifyUserId() == null || groupVerify.getVerifyUserId().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'verifyId'、'verifyGroupId'和'verifyUserId'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
												
			groupService.addGroupVerifyInfo(groupVerify);
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【添加验证信息成功】：" + groupVerify.getVerifyId());
			log.debug("【添加验证信息成功】：" + groupVerify.getVerifyId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 对验证信息进行验证URL: http://localhost:8099/hsim-bservice/group/updateGroupVerifyInfo
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/updateGroupVerifyInfo",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse updateGroupVerifyInfo(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			GroupVerify groupVerify = JSON.toJavaObject(object, GroupVerify.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			GroupVerify groupVerify = JSON.toJavaObject(JSON.parseObject(jsonStr), GroupVerify.class);*/
			
			//校验必要的参数
			if(groupVerify.getVerifyId() == null || groupVerify.getVerifyId().equals("") 
					|| groupVerify.getVerifyBy() == null || groupVerify.getVerifyBy().equals("")
					|| groupVerify.getVerifyResult() == null || groupVerify.getVerifyResult().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'verifyId()'、'verifyBy'和'verifyResult'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验验证信息是否能进行验证,如果此信息被验证过或者已经失效则不能够进行验证
			List<GroupVerify> groupVerifyList = new ArrayList<GroupVerify>();
			groupVerifyList = groupService.queryVerifyInfoByVerifyId(groupVerify);
			GroupVerify groupVerifyInList = groupVerifyList.get(0);
			String verifyResult = groupVerifyInList.getVerifyStatus();
			if(verifyResult.equals("N") || verifyResult.equals("Y")){   //当verifyResult为Y或者为N的时候，说明已经被验证过，不能进行验证操作
				resp.setRetCode(MessageResultEnum.REQ_VERIFIED.getRetCode());
				resp.setMessage(MessageResultEnum.REQ_VERIFIED.getMessage());
				log.debug(resp.getMessage());
				return resp;
			} else {
				//校验此验证信息是否失效，如果失效则不能被验证
				String verifyReqDateStr = groupVerifyInList.getVerifyReqDate();  //从数据中得到请求验证的时间字符串				
				int result = groupService.checkVerifyInfoOutDate(verifyReqDateStr);  //校验验证信息是否失效
				if(result < 0){		//验证信息失效，不能进行验证操作
					resp.setRetCode(MessageResultEnum.REQ_VOVERDUE_DATE.getRetCode());
					resp.setMessage(MessageResultEnum.REQ_VOVERDUE_DATE.getMessage());
					log.debug(resp.getMessage());
					return resp;
				}
			}
															
			groupService.updateGroupVerifyInfo(groupVerify);
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【验证成功】：" + groupVerify.getVerifyId());
			log.debug("【验证成功】：" + groupVerify.getVerifyId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 校验用户是否可以发送加入群请求URL: http://localhost:8099/hsim-bservice/group/sendGroupVerifyInfoCheck
	 * 返回信息中：verifyFlag为N表示不能发送，为Y表示能发送
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/sendGroupVerifyInfoCheck",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse sendGroupVerifyInfoCheck(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			GroupVerify groupVerify = JSON.toJavaObject(object, GroupVerify.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			GroupVerify groupVerify = JSON.toJavaObject(JSON.parseObject(jsonStr), GroupVerify.class);*/
			
			//校验必要的参数
			if(groupVerify.getVerifyGroupId() == null || groupVerify.getVerifyGroupId().equals("")
					|| groupVerify.getVerifyUserId() == null || groupVerify.getVerifyUserId().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'verifyGroupId'和'verifyUserId'都不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			List<GroupVerify> groupVerifyList = new ArrayList<GroupVerify>();
			groupVerifyList = groupService.queryUnverifiedInfoList(groupVerify); //查询用户在群中发送的未验证过的验证请求信息列表
			//如果查询列表为空或者验证信息超时，则可以再次发送请求，否则不行
			resp.setVerifyFlag("Y");
			if(groupVerifyList != null && groupVerifyList.size() > 0){
				for(GroupVerify unVerified : groupVerifyList){
					String verifyReqDateStr = unVerified.getVerifyReqDate();  //从数据中的到请求验证的时间字符串
					int result = groupService.checkVerifyInfoOutDate(verifyReqDateStr);   //校验验证信息是否失效
					if(result > 0){
						resp.setVerifyFlag("N");     //验证信息在有效期内，不能再次发送请求
						break;
					}
				}
			}
			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【校验用户是否可以发送加入群请求成功】：" + groupVerify.getVerifyGroupId());
			log.debug("【校验用户是否可以发送加入群请求成功】：" + groupVerify.getVerifyGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 根据verifyId查询验证信息URL: http://localhost:8099/hsim-bservice/group/queryVerifyInfoByVerifyId
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryVerifyInfoByVerifyId",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryVerifyInfoByVerifyId(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			GroupVerify groupVerify = JSON.toJavaObject(object, GroupVerify.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			GroupVerify groupVerify = JSON.toJavaObject(JSON.parseObject(jsonStr), GroupVerify.class);*/
			
			//校验必要的参数
			if(groupVerify.getVerifyId() == null || groupVerify.getVerifyId().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'verifyId'不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			List<GroupVerify> groupVerifyList = new ArrayList<GroupVerify>();
			groupVerifyList = groupService.queryVerifyInfoByVerifyId(groupVerify);
			int totalRows = groupVerifyList.size();
			//当验证结果verifyResult为I(未验证)时,如果验证信息失效,则设置为U(代表验证信息失效)
			for(GroupVerify groupVerifyInfo : groupVerifyList){
				if(groupVerifyInfo.getVerifyResult().equals("I")){
					String verifyReqDateStr = groupVerifyInfo.getVerifyReqDate();  //从数据中的到请求验证的时间字符串
					int result = groupService.checkVerifyInfoOutDate(verifyReqDateStr); //校验验证信息是否失效
					if(result > 0){
						groupVerifyInfo.setVerifyResult("I");    //验证信息在有效期内，设置verifyResult为I(未验证)
					} else {
						groupVerifyInfo.setVerifyResult("U");	 //验证信息不在有效期内，设置verifyResult为U(验证信息失效)
					}				
				}
			}
			resp.setRows(groupVerifyList);
			resp.setTotalRows(totalRows);
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【根据verifyId查询验证信息成功】：" + groupVerify.getVerifyId());
			log.debug("【根据verifyId查询验证信息成功】：" + groupVerify.getVerifyId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 修改公告URL: http://localhost:8099/hsim-bservice/group/addNotice
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/addNotice",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse addNotice(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Notice notice = JSON.toJavaObject(object, Notice.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Notice notice = JSON.toJavaObject(JSON.parseObject(jsonStr), Notice.class);*/
			
			//校验必要的参数
			if(notice.getNoticeGroupId() == null || notice.getNoticeGroupId().equals("")
					|| notice.getNoticeCreator() == null || notice.getNoticeCreator().equals("")
					|| notice.getNoticeContent() == null || notice.getNoticeContent().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'noticeCreator'、 'noticeContent'和'noticeGroupId'不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验操作人是不是群管理员
			Member member = new Member();
			member.setMemberGroupId(notice.getNoticeGroupId());
			member.setMemberUserId(notice.getNoticeCreator());
			String memberRole = groupService.queryUserRoleInGroup(member);
			if(!(memberRole.equals("H") || memberRole.equals("M"))){
				resp.setRetCode(MessageResultEnum.INSUFFICIENT_AUTHORITY.getRetCode());
				resp.setMessage(MessageResultEnum.INSUFFICIENT_AUTHORITY.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			groupService.setHisNoticeUnused(notice);  //修改群公告之前先把历史公告设置为"不使用"
			groupService.addNotice(notice);
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【修改群公告成功】：" + notice.getNoticeGroupId());
			log.debug("【修改群公告成功】：" + notice.getNoticeGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 撤销群公告URL: http://localhost:8099/hsim-bservice/group/setHisNoticeUnused
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/setHisNoticeUnused",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse setHisNoticeUnused(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Notice notice = JSON.toJavaObject(object, Notice.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Notice notice = JSON.toJavaObject(JSON.parseObject(jsonStr), Notice.class);*/
			
			//校验必要的参数
			if(notice.getNoticeGroupId() == null || notice.getNoticeGroupId().equals("")
					|| notice.getNoticeCreator() == null || notice.getNoticeCreator().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'noticeGroupId'和'noticeCreator'不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			//校验操作人是不是群管理员
			Member member = new Member();
			member.setMemberGroupId(notice.getNoticeGroupId());
			member.setMemberUserId(notice.getNoticeCreator());
			String memberRole = groupService.queryUserRoleInGroup(member);
			if(!(memberRole.equals("H") || memberRole.equals("M"))){
				resp.setRetCode(MessageResultEnum.INSUFFICIENT_AUTHORITY.getRetCode());
				resp.setMessage(MessageResultEnum.INSUFFICIENT_AUTHORITY.getMessage());
				log.debug(resp.getMessage());
				return resp;
			}
			
			groupService.setHisNoticeUnused(notice);
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			System.out.println("【撤销群公告成功】：" + notice.getNoticeGroupId());
			log.debug("【撤销群公告成功】：" + notice.getNoticeGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
	
	/**
	 * 查询群公告URL: http://localhost:8099/hsim-bservice/group/queryNoticeInfo
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryNoticeInfo",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryNoticeInfo(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();
		try {
			//获取前端传过来的数据
			JSONObject object = (JSONObject)request.getAttribute("object");
			Notice notice = JSON.toJavaObject(object, Notice.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//不鉴权时获取前端传过来的数据
			/*InputStream is = null;
			is = request.getInputStream();			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);

			Notice notice = JSON.toJavaObject(JSON.parseObject(jsonStr), Notice.class);*/
			
			//校验必要的参数
			if(notice.getNoticeGroupId() == null || notice.getNoticeGroupId().equals("")){
				resp.setRetCode(MessageResultEnum.PARAMETER_NOT_ENOUGH.getRetCode());
				resp.setMessage(MessageResultEnum.PARAMETER_NOT_ENOUGH.getMessage()+",'noticeGroupId'不能为空!");
				log.debug(resp.getMessage());
				return resp;
			}
			
			List<Notice> noticeList = new ArrayList<Notice>();
			noticeList = groupService.queryNoticeInfo(notice);
			int totalRows = noticeList.size();
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setRows(noticeList);
			resp.setTotalRows(totalRows);
			System.out.println("【查询群公告信息成功】：" + notice.getNoticeGroupId());
			log.debug("【查询群公告信息成功】：" + notice.getNoticeGroupId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
		}
       return resp;
	}
}
